local hx__yinxing = fk.CreateSkill{
  name = "hx__yinxing",
  tags = { Skill.Compulsory },
}

local U = require "packages/utility/utility"

hx__yinxing:addEffect(fk.DamageCaused, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return data.from == player and player:hasSkill(hx__yinxing.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1,hx__yinxing.name)
    for _, p in ipairs(room.alive_players) do
      for _, skill in ipairs(p:getSkillNameList()) do
        local s = Fk.skills[skill]
        if s:hasTag(Skill.Switch) then
          U.SetSwitchSkillState(p, skill, fk.SwitchYin)
        end
      end
    end
  end,
})

hx__yinxing:addEffect(fk.TurnStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__yinxing.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1,hx__yinxing.name)
    for _, p in ipairs(room.alive_players) do
      for _, skill in ipairs(p:getSkillNameList()) do
        local s = Fk.skills[skill]
        if s:hasTag(Skill.Switch) then
          U.SetSwitchSkillState(p, skill, fk.SwitchYin)
        end
      end
    end
  end,
})

hx__yinxing:addEffect(fk.DamageInflicted, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return data.to == player and player:hasSkill(hx__yinxing.name) and data.from and data.card.skillName ~= hx__yinxing.name
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useVirtualCard("slash", nil, data.from, {player}, hx__yinxing.name, true)
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = hx__yinxing.name,
    })
    room:invalidateSkill(player, hx__yinxing.name,"-turn")
  end,
})


return hx__yinxing